﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../CSS/style1.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/style4.css" rel="stylesheet" type="text/css" />
    <script src="../JS/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.pager.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.showModalDialog.js" type="text/javascript"></script>
    <script type="text/javascript">
        //CSS样式表的格式
        function Load1() {
            $(".menuDiv div").live("click", function () {
                $(".menuDiv div").css("background-image", "url()");
                $(this).css("background-image", "url(../images/bg.gif)");
                $(".contentDiv div").hide();
                $(".contentDiv div:eq(" + $(this).index() + ")").show();
            });
        };
        var CusID;
        function Load2() {
            $("#dataLeft .dataTable tr:gt(0)").live("click", function () {
                $("#dataLeft .dataTable tr:gt(0)").css("background-color", "white");
                $(this).css("background-color", "red");
                $(".menuDiv div:first").css("background-image", "url(../images/bg.gif)");
                $(".menuDiv div:last").css("background-image", "url()");
                $(".contentDiv div:first").show();
                $(".contentDiv div:last").hide();
                CusID = $(this).attr("id");
                
                reloadLinkMan();
                reloadActivitys();
                
                
            });
        }
        //时间格式转换
        function date2str(date) {
            //null判断
            if (date == null) return "";
            //去掉左右的斜杠
            date = date.replace(/\//g, "");
            //将其转为一个日期对象
            eval("var d = new " + date + ";");
            //返回最终结果
            return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
        }
        //全部加载内容
        $(function () {
            Load1();
            Load2();
            reloadCustomer();
        });
        //查询客户信息管理页面
        function cha() {
            var cus = {
                action: "SelectCustomer",
                CusName: $("#txtCusName").val(),
                CusID: $("#txtCusID").val()
            };
            $("#pageDiv").empty().pager3("CustomerAll.ashx", cus, function (data) {
                //展示查询的结果
                $("#tbb1 tr:gt(0)").remove();
                var tb1 = $("#tbb1").get(0);
                for (var i = 0; i < data.length; i++) {
                    var tr = tb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = data[i].CusID || "";
                    tr.insertCell(-1).innerHTML = data[i].CusName || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].CusDate) || "";
                    tr.insertCell(-1).innerHTML = data[i].CusMan || "";
                    tr.insertCell(-1).innerHTML = '<img src="../images/33.gif" title="编辑" onclick="showCustomer(' + data[i].ID + ')" />' || "";
                }
            });
        }
        //加载 Customer(客户信息) 表的全部内容
        function reloadCustomer() {
            //注册分页器控件
            $("#pageDiv").empty().pager2("QuanBuAll.asmx/paging", {}, function (data) {
                //展示查询的结果
                $("#tbb1 tr:gt(0)").remove();
                var tbb1 = $("#tbb1").get(0);
                for (var i = 0; i < data.length; i++) {
                    var tr = tbb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = data[i].CusID || "";
                    tr.insertCell(-1).innerHTML = data[i].CusName || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].CusDate) || "";
                    tr.insertCell(-1).innerHTML = data[i].CusMan || "";
                    tr.insertCell(-1).innerHTML = '<img src="../images/33.gif" title="编辑" onclick="showCustomer(' + data[i].ID + ')" />' || "";
                    $(tr).attr("id", data[i].CusID);
                }
            });
        }

        //加载 LinkMan(联系人) 表的全部内容
        function reloadLinkMan() {
            //注册分页器控件
            $.ajax({
                url: "QuanBuAll.asmx/SelectLinkMans",
                type: "post",
                data: JSON.stringify({ CusID: CusID }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    $("#tab2 tr:gt(0)").remove();
                    var tab2 = $("#tab2").get(0);
                    for (var i = 0; i < obj.d.length; i++) {
                        var tr = tab2.insertRow(-1);
                        tr.insertCell(-1).innerHTML = obj.d[i].LMName || "";
                        tr.insertCell(-1).innerHTML = obj.d[i].LMSex || "";
                        tr.insertCell(-1).innerHTML = obj.d[i].LMDuty || "";
                        tr.insertCell(-1).innerHTML = obj.d[i].LMOfficeNo || "";
                        tr.insertCell(-1).innerHTML = obj.d[i].LMMobileNo || "";
                        tr.insertCell(-1).innerHTML = '<img title="编辑" src="../images/33.gif" onclick="showLinkMan(' + obj.d[i].LMID + ')" />&nbsp;&nbsp;<img title="删除" onclick="editLinkMan(' + obj.d[i].LMID + ');" src="../images/11.gif" />' || "";
                    }
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });

        }

        //加载 Activitys(交往记录) 表的全部内容
        function reloadActivitys() {
            //注册分页器控件

            $.ajax({
                url: "QuanBuAll.asmx/SelectActivitys",
                type: "post",
                data: JSON.stringify({ CusID: CusID }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    $("#tab3 tr:gt(0)").remove();
                    var tab3 = $("#tab3").get(0);
                    for (var i = 0; i < obj.d.length; i++) {
                        var tr = tab3.insertRow(-1);
                        tr.insertCell(-1).innerHTML = date2str(obj.d[i].ActDate) || "";
                        tr.insertCell(-1).innerHTML = obj.d[i].ActAdd || "";
                        tr.insertCell(-1).innerHTML = obj.d[i].ActTitle || "";
                        tr.insertCell(-1).innerHTML = obj.d[i].ActDesc || "";
                        tr.insertCell(-1).innerHTML = '<img title="编辑" src="../images/33.gif" onclick="showActivitys(' + obj.d[i].ActID + ')" />&nbsp;<img title="删除" onclick="editActivitys(' + obj.d[i].ActID + ')" src="../images/11.gif" />' || "";
                    }
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });
        }
        //修改客户信息表
        function showCustomer(id) {

            $.showModalDialog("CustomerEdit.htm?data=" + Math.random(), { id: id }, 600, 400, function (r) {
                reloadCustomer();
            });

        }
        //添加联系人表
        function showLinkMan1() {

            $.showModalDialog("LinkManAdd.htm?data=" + Math.random(), { CusID: CusID }, 600, 300, function (r) {
                reloadLinkMan();
            });
        }
        //修改联系人表
        function showLinkMan(id) {
            
            $.showModalDialog("LinkManEdit.htm?data=" + Math.random(), { id: id }, 600, 300, function (r) {
                reloadLinkMan();
            });
        }
        //删除联系人表
        function editLinkMan(id) {
            //询问
            if (!confirm("您确定要删除吗？")) return;
            $.ajax({
                url: "QuanBuAll.asmx/DeleteLinkMans",
                type: "post",
                data: JSON.stringify({ id: parseInt(id) }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    alert(obj.d ? "删除成功" : "删除失败");
                    reloadLinkMan();
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });

        }
        //添加交往记录表
        function showActivitys1() {

            $.showModalDialog("ActivitysAdd.htm?data=" + Math.random(), { CusID: CusID }, 600, 300, function (r) {
                reloadActivitys();
            });
        }
        //修改交往记录表
        function showActivitys(id) {

            $.showModalDialog("ActivitysEdit.htm?data=" + Math.random(), { id: id }, 600, 300, function (r) {
                reloadActivitys();
            });
        }

        //删除交往记录表
        function editActivitys(id) {
            //询问
            if (!confirm("您确定要删除吗？")) return;
            $.ajax({
                url: "QuanBuAll.asmx/DeleteActivitys",
                type: "post",
                data: JSON.stringify({ id: parseInt(id) }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    alert(obj.d ? "删除成功" : "删除失败");
                    reloadActivitys();
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });

        }
        
    </script>
</head>
<body>
    <div id="desDiv">
        <span>客户信息管理</span><br />
        维护客户信息，记录客户联系电话和交往记录
    </div>
    <table class="tableEdit">
        <tr>
            <th>
                客户名称：
            </th>
            <td>
                <input type="text" id="txtCusName" style="color:blue;width:140px" />
            </td>
            <th>
                客户编号：
            </th>
            <td>
                <input type="text" id="txtCusID" style="color:blue;width:140px" />
            </td>
        </tr>
        <tfoot>
            <tr>
                <td colspan="8">
                    <input type="button" value="查询" onclick="cha();" />
                </td>
            </tr>
        </tfoot>
    </table>
    <br />
    <div style="width: 1065px">
        <div id="dataLeft">
            <table class="dataTable" id="tbb1">
                <tr>
                    <th align="center">
                        客户编号
                    </th>
                    <th align="center">
                        客户名称
                    </th>
                    <th align="center">
                        建立时间
                    </th>
                    <th align="center">
                        客户经理
                    </th>
                    <th align="center">
                        操作
                    </th>
                </tr>

            </table>
            <div id="pageDiv">
            </div>
        </div>
        <div id="dataRight">
            <div class="menuDiv">
                <div>联系人
                </div>
                <div>交往信息
                </div>
            </div>
            <div class="contentDiv">
                <div>
                    <a href="javascript:showLinkMan1()">新建联系人</a>
                    <table class="dataTable" id="tab2">
                        <tr>
                            <th align="center">
                                姓名
                            </th>
                            <th align="center">
                                性别
                            </th>
                            <th align="center">
                                职位
                            </th>
                            <th align="center">
                                固定电话
                            </th>
                            <th align="center">
                                手机号码
                            </th>
                            <th align="center">
                                操作
                            </th>
                        </tr>

                    </table>
                </div>
                <div><a href="javascript:showActivitys1()">新建交往记录</a>
                    <table class="dataTable" id="tab3">
                        <tr>
                            <th align="center">
                                时间
                            </th>
                            <th align="center">
                                地点
                            </th>
                            <th align="center">
                                概要
                            </th>
                            <th align="center">
                                描述
                            </th>
                            <th align="center">
                                操作
                            </th>
                        </tr>

                    </table>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
